package cn.crce.cloud9.simple;

import java.text.NumberFormat;

/**
 * @author OnCloud9
 * @description
 * @project NRCE-TEST
 * @date 2022年09月10日 上午 09:42
 */
public class Case23 {
    public static void main(String[] args) {
        Person2[] people = new Person2[2];
        people[0] = new Worker("老张", 30000);
        people[1] = new Student2("小王", "计算机科学");
        for (int i = 0; i < people.length; i++) {
            Person2 p = people[i];
            //*********Found**********
            System.out.println(p.getName() + ", " + p.getDescription());
        }
    }
}


//*********Found**********
abstract class Person2 {
    public Person2(String n) {
        name = n;
    }

    //*********Found**********
    public abstract String getDescription();

    public String getName() {
        return name;
    }

    private String name;
}

//*********Found**********
class Worker extends Person2 {
    public Worker(String n, double s) {
        super(n);
        salary = s;
    }

    public String getDescription() {
        NumberFormat formatter = NumberFormat.getCurrencyInstance();
        return "工人，年薪是 " + formatter.format(salary) + "。";
    }

    private double salary;
}

//*********Found**********
class Student2 extends Person2 {
    public Student2(String n, String m) {
        super(n);
        major = m;
    }

    public String getDescription() {
        return "学生，专业是 " + major + "。";
    }

    private String major;
}
